/**
 * 版权所有（c）2021. 上海海鼎信息工程股份有限公司，保留所有权利
 */
package com.lovely602.design.creation.builder.demo;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.InputStream;

/**
 * 客厅
 *
 * @author lizhixing
 */
public class Parlour {

  /**
   * 墙
   */
  private String wall;
  /**
   * 电视
   */
  private String tv;
  /**
   * 沙发
   */
  private String sofa;

  public void setWall(String wall) {
    this.wall = wall;
  }

  public void setTV(String tv) {
    this.tv = tv;
  }

  public void setSofa(String sofa) {
    this.sofa = sofa;
  }

  public void show() {
    JFrame jf = new JFrame("建造者模式测试");
    Container contentPane = jf.getContentPane();
    JPanel p = new JPanel();
    JScrollPane sp = new JScrollPane(p);
    String parlour = wall + tv + sofa;

    try {
      InputStream is = ClassLoader.getSystemResourceAsStream("image/" + parlour + ".jpg");
      Image image = ImageIO.read(is);
      JLabel l = new JLabel(new ImageIcon(image));
      p.setLayout(new GridLayout(1, 1));
      p.setBorder(BorderFactory.createTitledBorder("客厅"));
      p.add(l);
      contentPane.add(sp, BorderLayout.CENTER);
      jf.pack();
      jf.setVisible(true);
      jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } catch (IOException e) {
      e.printStackTrace();
    }

  }
}
